layui.use(['layer', 'form', 'admin', 'ax', 'laydate'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var layer = layui.layer;
    var laydate = layui.laydate;

    //执行一个laydate实例
    laydate.render({
        elem: '#rq', //指定元素
        type: 'date'
    });

    /**
     * 检索店名
     */

    var languageAjax = new $ax(Feng.ctxPath + "/btyTxl/getDm");
    var languageResult = languageAjax.start();
    $.each(languageResult, function (index, val) {
        $("#dm").append("<option value='" + val.id + "'>" + val.dm + "</option>");
    });

    form.render('select');


    /**
     * 检索区域
     */
    var qyAjax = new $ax("/area/getAreaByType");
    qyAjax.set("type", 2);
    var qyResult = qyAjax.start();
    $.each(qyResult, function (index, data) {
        $("#provinceName").append("<option value='" + data.id + "'>" + data.simpleName + "</option>");
    });
    form.render('select');
    form.on('select(provinceName)', function (data) {
        var provinceId = data.value;
        if (provinceId == "") {
            $("#cityName").html("");
            $("#cityName").append("<option value=''>全部</option>");
            form.render('select');
        } else {
            var qyAjax = new $ax("/area/getAreaByPid");
            qyAjax.set("pid", provinceId);
            var qyResult = qyAjax.start();
            $("#cityName").html("");
            $("#cityName").append("<option value=''>全部</option>");
            $.each(qyResult, function (index, data) {
                $("#cityName").append("<option value='" + data.id + "'>" + data.simpleName + "</option>");
            });
            form.render('select');
        }
    });


// 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/archives/addItem", function (data) {


                Feng.success("添加成功!");
                admin.putTempData('formOk', true);
                admin.closeThisDialog();


        }, function (data) {
            Feng.error("添加失败!");
        });
        ajax.set(data.field);
        ajax.set("qy",$("#provinceName option:selected").text());
        ajax.set("eqy",$("#cityName option:selected").text());
        ajax.set("dm", $("#dm option:selected").text());
        ajax.start();
        //添加 return false 可成功跳转页面
        return false;
    });

});
